Skip to content

fix: support openai SDK v2 — wrap parse() on non-beta path, isolate wrapper errors#1326

Open
serhiizghama wants to merge 1 commit intoAgentOps-AI:mainfrom
serhiizghama:fix/issue-1260-openai-beta-chat-module-not-found
Open

fix: support openai SDK v2 — wrap parse() on non-beta path, isolate wrapper errors#1326
serhiizghama wants to merge 1 commit intoAgentOps-AI:mainfrom
serhiizghama:fix/issue-1260-openai-beta-chat-module-not-found

Conversation

@serhiizghama
Copy link
Copy Markdown

Problem

In openai >= 2.0, the structured output .parse() method moved from openai.resources.beta.chat.completions to openai.resources.chat.completions. The current instrumentor always tries the beta path, which raises ModuleNotFoundError: No module named 'openai.resources.beta.chat' on newer SDK versions.

A secondary issue: all wrappers are in a single try/except, so when the beta path fails, the Responses API wrappers (openai.resources.responses) are silently skipped too — meaning users on openai v2 lose both structured output tracing and Responses API tracing.

Closes #1260

Changes

  • Try chat.completions.parse first (current SDK location in openai >= 2.0)
  • Fall back to beta.chat.completions.parse for backwards compatibility with openai < 2.0
  • Split into separate try/except blocks so a failure in one wrapper group (e.g. beta path) doesn't prevent other wrappers from being installed

Testing

Install agentops with openai >= 2.0 and verify:

  1. No [OPENAI INSTRUMENTOR] Error setting up OpenAI streaming wrappers: No module named 'openai.resources.beta.chat' warning on startup
  2. Structured output calls using .parse() are traced correctly
  3. Responses API calls are traced correctly

Also tested with openai < 2.0 to confirm backwards compatibility via the legacy beta fallback path.

In openai >= 2.0, the structured output .parse() method moved from
openai.resources.beta.chat.completions to openai.resources.chat.completions.
The old code wrapped all methods in a single try/except, so a ModuleNotFoundError
on the beta path would silently skip the Responses API wrappers too.

Changes:
- Try chat.completions.parse first (current SDK location)
- Fall back to beta.chat.completions.parse for openai < 2.0 compatibility
- Split into separate try/except blocks so a failure in one group
  doesn't prevent other wrappers (e.g. Responses API) from being installed

Fixes AgentOps-AI#1260
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: charmap and No module named 'openai.resources.beta.chat'

1 participant